package com.ccx.library.module.perm.controller;

import com.ccx.library.module.perm.entity.Perm;
import com.ccx.library.module.perm.service.PermService;
import com.ccx.library.response.R;
import com.ccx.library.util.ModelVoIdUtil;
import com.ccx.library.util.WrapperUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/perm")
public class PermController {
    @Autowired
    private PermService permService;

    @GetMapping("/query")
    public R Query(Perm perm){
        return R.SUCCESS(permService.getOne(WrapperUtil.Query(perm)));
    }

    @PostMapping
    public R save(@RequestBody Perm perm){
        return R.SUCCESS(permService.save(perm));
    }

    @PutMapping
    public R edit(@RequestBody Perm perm){
        return R.SUCCESS(permService.update(WrapperUtil.Update(perm, ModelVoIdUtil.getId(perm), perm.getPermId())));
    }

    @DeleteMapping
    public R DeleteBatch(@RequestBody List<String> ids){
        return R.SUCCESS(permService.removeByIds(ids));
    }
}
